<!doctype html>
<html lang="en" ng-app="app">
<head>
	<base href="${ctx_path}/" />
	<meta charset="UTF-8">
	<title>数据处理</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<script type="text/javascript" src="res/js/jquery-1.10.1.min.js"></script>
	<link rel="stylesheet" href="res/css/reset.css"/>
	<link rel="stylesheet" href="res/css/function.css"/>
	<link rel="stylesheet" href="res/css/main.css"/>
	<script type="text/javascript" src="res/js/jquery-1.10.1.min.js"></script>
	<script type="text/javascript" src="res/js/jquery-utils.js"></script>
	<script type="text/javascript" src="res/js/jquery-modal.js"></script>
</head>
<body ng-controller="DataController">
	<header>
		<div>业务单据</div>
		<div class="clearfix"></div>
	</header>
	<div>
		<div>
			导入表头: <input type="file" ng-file-select="onHeadFile($files)">
			导入数据: <input type="file" ng-file-select="onDatasFile($files)" >
			
			<button  ng-click="importData();">导入数据</button>
		</div>
		<div class="t-table">
			<table>
				<thead>
					<tr>
						<!-- <th><input type="checkbox"></th> -->
						<th nowrap>编号</th>
						<th nowrap>名字</th>
						<th nowrap>表名</th>
						<th nowrap>字段</th>
						<th nowrap >操作</th>
					</tr>
				</thead>
				<tbody>
					<tr ng-repeat="table in tables">
						<!-- <td><input type="checkbox"></td> -->
						<td ng-bind="table.id"></td>
						<td ng-bind="table.name"></td>
						<td ng-bind="table.item"></td>
						<td ng-bind="table.value"></td>
						<td>
							<button type="button" ng-click="" class="btn btn-orange btn-mini">修改</button>
							<button type="button" ng-click="" class="btn btn-orange btn-mini">删除</button>
							<button type="button" ng-click="load(table);" class="btn btn-orange btn-mini">查看数据</button>
							<button type="button" ng-click="" class="btn btn-orange btn-mini">清空数据</button>
						</td>
					</tr>
				</tbody>
			</table>
			
		</div>
	</div>
	<div id="loading" style="display:none;" class="loaders">
      <div class="loader">
          <div class="loader-inner ball-pulse">
              <div></div><div></div><div></div>
          </div>
      </div>
	</div>
	<script type="text/javascript" src="res/lib/angular.js"></script>
	<script type="text/javascript" src="res/lib/angular-file-upload.min.js"></script>
	<script type="text/javascript">
	var app = angular.module('app', ['ngFileUpload']);
	app.controller('DataController', function($scope, $http, $upload){
		
		$http({method:'post',
            url:"findAll",
            params:{}
        }).success(function(result){
        	if(result.status == 1){
	           	$scope.tables = result.tables;
        	}else{
        		alert(result.msg);
        	}
        }).error(function(){
            alert("网络连接失败");
        });
		$scope.onHeadFile = function(files){
	         var file = files[0];
	         if (file == null) return;
	        
	         $scope.upload = $upload.upload({
	             url: "uploadHead?table_name=datas", 
	             file: file, 
	             fileName: file.name 
	         }).progress(function(evt) {        
	         }).success(function(data, status, headers, config) {        
	               alert(data.msg);
	         });   
		 }
		 
		 $scope.load = function(table){
			 window.location.href = "load?type="+table.item
		 }
	});
	
	app.factory('myInterceptor', function(){		
		return Common.requestInterceptor;
	});
	
	app.config(['$httpProvider', function($httpProvider) {
	    $httpProvider.interceptors.push('myInterceptor');
	}]);
	</script>	
</body>
</html>